package com.yuexunit.finance.member.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.member.entity.FinanceFollowInfoEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;
import com.yuexunit.util.DateUtil;

/**
*@version 创建时间：2016年9月20日 上午11:11:21
*@author wenwenlong
*类说明
*/

@Implements(FinanceFollowInfoService.class)
public class FinanceFollowInfoServiceImpl implements FinanceFollowInfoService {

	@Override
	@Transactional
	public Long createFinanceFollowInfo(FinanceFollowInfoEntity entity) {
		entity.setCreateDateTime(DateUtil.now());
		entity.setUpdateDateTime(DateUtil.now());
		entity.setSubmitState(Boolean.FALSE);
		PersistUtil.insert(entity);
		return entity.getFollowInfoId();
	}

	@Override
	@Transactional
	public void updateFinanceFollowInfo(FinanceFollowInfoEntity entity) {
		entity.setUpdateDateTime(DateUtil.now());
		PersistUtil.update(entity);
	}

	@Override
	@Transactional
	public void deleteFinanceFollowInfo(Long followInfoId) {
		PersistUtil.delete(FinanceFollowInfoEntity.class, followInfoId);
	}

	@Override
	public FinanceFollowInfoEntity inquireFinanceFollowInfo(Long followInfoId) {
		return PersistUtil.get(FinanceFollowInfoEntity.class, followInfoId);
	}

	@Override
	public List<FinanceFollowInfoEntity> inquireFinanceFollowInfoList(Long followId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceFollowInfoEntity.class);
		criteria.add(Restrictions.eq("followId", followId));
		criteria.addOrder(Order.desc("createDateTime"));
		return PersistUtil.get(criteria);
	}

	@Override
	public PageList<FinanceFollowInfoEntity> inquireFinanceFollowInfoList(PageCriteria page) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceFollowInfoEntity.class);
		criteria.addOrder(Order.desc("createDateTime"));
		return PersistUtil.get(criteria, page);
	}
}
